#ifndef WF_TRANSITION_H
#define WF_TRANSITION_H

#include <btime.h>
#include <inodedata.h>
#include <itransition.h>
#include <node.h>

#include <QtCore/QObject>
#include <QtCore/QPointer>

using namespace core;
using namespace net;

namespace core
{
class DirectedGraph;
}

namespace wfnet
{
class Arc;
class Expression;
class WfNet;

class Transition : public QObject, /*implements*/public ITransition,
    public INodeData
{
    Q_OBJECT

public:
    ~Transition();

    // IIdentifiable
    nid getId() const;

    // ITransition
    QString name() const;

    IExpression* getGuard() const;
    core::BasicTime getDelay() const;

    void setGuard(IExpression* guard);
    void setDelay(const core::BasicTime& time);

    QSet<const IPlace* > getInputPlaces() const;
    QSet<const IPlace* > getOutputPlaces() const;

    void fire(const BasicTime& globalClock);

    // INodeData
    void registerNode(Node* node);
    const Node* const node() const;

    bool check() const;

protected:
    Transition(WfNet* parent, nid id,
        QString name, BasicTime delay = 0);

private:
    QSet<const Arc* > getInputArcs(const DirectedGraph& graph) const;
    QSet<const Arc* > getOutputArcs(const DirectedGraph& graph) const;

private:
    friend class WfNet;

    Node* m_node; // guarded pointer
    nid m_id;
    QString m_name;
    QPointer<Expression> m_guard;
    BasicTime m_delay;
};

} // namespace wfnet

#endif
